package com.aischool.webapp.family;

import com.aischool.params.AiNotesParams;
import com.aischool.routes.RouteMapping;
import com.aischool.service.AiNotesService;
import com.aischool.utils.AppUtil;
import com.aischool.utils.DateUtil;
import com.aischool.utils.JsonCodeEnum;
import com.aischool.utils.JsonResult;
import com.aischool.utils.StringUtil;
import com.jfinal.aop.Inject;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Record;

@RouteMapping(url = "/front/family/notes")
public class NotesController extends BaseFamilyController {
	
	@Inject
	AiNotesService aiNotesService;

	public void index() {
		render(view_path + "/notes.html");
	}
	
	public void getPage() {
		// 结果类
		JsonResult jr = new JsonResult();
		// 参数类
		AiNotesParams params = new AiNotesParams();
		
		// 获取参数
		int login_org_id = this.getAttrForInt("login_org_id");	
		int login_class_id = this.getAttrForInt("login_class_id");		
		
		params.setPageNo(getParaToInt("pageNo", 1));
		params.setPageSize(getParaToInt("pageSize", AppUtil.Default_PageSize));
		
		params.setOrgId(login_org_id);
		params.setClassId(login_class_id);
		
		params.setState(1);

		// 获取分页
		Object pageData = aiNotesService.getPage(params);
		
		jr.setDicKV("pageData", pageData);
		
		
		jr.setEnum(JsonCodeEnum.Success);
		renderJson(jr.Dic);
		
	}
	
	public void detaile() {

		int id = getInt("id", 0);
		if (id>0) {
			Record rd = aiNotesService.getOne(id);
			if (StrKit.notBlank(rd.getStr("note_pics"))) {
				this.set("note_pics", StringUtil.trim(rd.getStr("note_pics"), ';').split(";"));
			}
			if (StrKit.notBlank(rd.getStr("node_videos"))) {
				this.set("node_videos", StringUtil.trim(rd.getStr("node_videos"), ';').split(";"));
			}
			this.setAttr("add_time", DateUtil.getDate(rd.getDate("add_time"), "yyyy年MM月dd日"));
			this.setAttr("note_rd", rd);
		}
		render(view_path + "/notes-detaile.html");
	}
}
